<template>
  <el-table :data="tableData" style="width: 100%">
    <el-table-column label="入职时间" width="180">
      <template slot-scope="scope">
        <i class="el-icon-time"></i>
        <span style="margin-left: 10px">{{ scope.row.date }}</span>
      </template>
    </el-table-column>
    <el-table-column label="姓名" width="180">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>姓名: {{ scope.row.name }}</p>
          <p>家庭住址: {{ scope.row.address }}</p>
          <div slot="reference" class="name-wrapper">
            <el-tag size="medium">{{ scope.row.name }}</el-tag>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
          >编辑</el-button
        >
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)"
          >删除</el-button
        >
        <!-- 编辑弹框 -->
        <el-dialog title="员工信息" :visible.sync="dialogFormVisible">
          <el-form :model="row">
            <el-form-item label="姓名" :label-width="formLabelWidth">
              <el-input v-model="row.name" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <el-form :model="row">
            <el-form-item label="电话" :label-width="formLabelWidth">
              <el-input v-model="row.phone" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <el-form :model="row">
            <el-form-item label="家庭住址" :label-width="formLabelWidth">
              <el-input v-model="row.address" autocomplete="off"></el-input>
            </el-form-item>
          </el-form>
          <div slot="footer" class="dialog-footer">
            <el-button @click="cancel">取 消</el-button>
            <el-button type="primary" @click="betrue(scope.$index, scope.row)"
              >确 定</el-button
            >
          </div>
        </el-dialog>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  props: {
    tableData: Array,
  },
  data() {
    return {
      formLabelWidth: "120px",
      dialogFormVisible: false,
      row: {},
      oldrow: {}
    };
  },
  methods: {
    //点击编辑显示弹框
    handleEdit(index, row) {
      this.dialogFormVisible = true;
      let copy = Object.assign({}, row)
      this.row = copy
    },
    //删除某项数据
    handleDelete(index, row) {
      this.$emit('removeRow',row);
    },
    //取消修改信息
    cancel() {
      this.dialogFormVisible = false;
    },
    betrue(index, row) {
        let copy = Object.assign({}, this.row)
        this.dialogFormVisible=false,
        row = copy
        this.$emit('changeRow',row);
    }
  },
  computed: {},
};
</script>
